﻿using University.Workshop.DataAccess;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using University.Workshop.Model;
using System.Collections.ObjectModel;
using University.Workshop.Business;

namespace University.Workshop.Tests
{
    
    
    /// <summary>
    ///This is a test class for GiftCardDataAccessTest and is intended
    ///to contain all GiftCardDataAccessTest Unit Tests
    ///</summary>
    [TestClass()]
    public class GiftCardDataAccessTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        

        /// <summary>
        ///A test for NewGiftCard
        ///</summary>
        [TestMethod()]
        public void NewGiftCardTest()
        {
            // TODO: Initialize to an appropriate value
            GiftCard expected = null; // TODO: Initialize to an appropriate value
            GiftCard actual = null;

            string firstName = "Pedro"; // TODO: Initialize to an appropriate value
            string lastName = "Suarez"; // TODO: Initialize to an appropriate value
            char gender = 'M'; // TODO: Initialize to an appropriate value
            Random rand = new Random();
            DateTime birthday = DateTime.Now.AddYears(-18); // TODO: Initialize to an appropriate value
            string email = "pedro" + rand.Next(400) + "@gmail.com"; // TODO: Initialize to an appropriate value
            //string email = "juan@hotmail.com";
            string password = "qwert1"; // TODO: Initialize to an appropriate value
            string rePassword = "qwert1"; // TODO: Initialize to an appropriate value
            string department = "Cochabamba"; // TODO: Initialize to an appropriate value
            string city = "Cercado"; // TODO: Initialize to an appropriate value
            string movilephone = "" + rand.Next(79999999); // TODO: Initialize to an appropriate value
            string phone = "" + rand.Next(4999999); // TODO: Initialize to an appropriate value
            Collection<RegisterError> ac;
            ac = UserRegistrationManager.RegisterUser(firstName, lastName, gender, birthday, email, password, rePassword, department, city, movilephone, phone);

            
            User act;
            act = UserDataAccess.GetUserByEmail(email);

            long userIdSender = act.Id ;
            long userIdRecipient = act.Id;
            float quantity = 10;
            string currency = "Bolivianos";
            string notification = "Yes";
            string available = "Yes";
            expected = GiftCardManager.NewGiftCard(userIdSender, userIdRecipient, quantity, currency, notification, available);
            Assert.AreNotEqual(actual, expected);
        }

        /// <summary>
        ///A test for ModifyQuantity
        ///</summary>
      /*  [TestMethod()]
        public void ModifyQuantityTest()
        {
            string firstName = "Pedro"; // TODO: Initialize to an appropriate value
            string lastName = "Suarez"; // TODO: Initialize to an appropriate value
            char gender = 'M'; // TODO: Initialize to an appropriate value
            Random rand = new Random();
            DateTime birthday = DateTime.Now.AddYears(-18); // TODO: Initialize to an appropriate value
            string email = "pedro" + rand.Next(400) + "@yahoo.com"; // TODO: Initialize to an appropriate value
            //string email = "juan@hotmail.com";
            string password = "qwert1"; // TODO: Initialize to an appropriate value
            string rePassword = "qwert1"; // TODO: Initialize to an appropriate value
            string department = "Cochabamba"; // TODO: Initialize to an appropriate value
            string city = "Cercado"; // TODO: Initialize to an appropriate value
            string movilephone = "" + rand.Next(79999999); // TODO: Initialize to an appropriate value
            string phone = "" + rand.Next(4999999); // TODO: Initialize to an appropriate value
            Collection<RegisterError> ac;
            ac = UserRegistrationManager.RegisterUser(firstName, lastName, gender, birthday, email, password, rePassword, department, city, movilephone, phone);


            User act;
            act = UserDataAccess.GetUserByEmail(email);

            long userIdSender = act.Id;
            long userIdRecipient = act.Id;
            float quantity = 10;
            string currency = "Bolivianos";
            string notification = "Yes";
            string available = "Yes";
            GiftCard gf = GiftCardManager.NewGiftCard(userIdSender, userIdRecipient, quantity, currency, notification, available);
            float pquantity = 12;
            gf = GiftCardManager.ModifyGiftCard(userIdSender, userIdRecipient, pquantity, currency, notification, available);
            //Assert.AreEqual(expected, expected);
        }

        /// <summary>
        ///A test for ModifyGiftCard
        ///</summary>
        [TestMethod()]
        public void ModifyGiftCardTest()
        {
            ModifyQuantityTest();
        }
        */
        /// <summary>
        ///A test for UserHasNewCredit
        ///</summary>
        [TestMethod()]
        public void UserHasNewCreditTest()
        {
            string firstName = "Pedro"; // TODO: Initialize to an appropriate value
            string lastName = "Suarez"; // TODO: Initialize to an appropriate value
            char gender = 'M'; // TODO: Initialize to an appropriate value
            Random rand = new Random();
            DateTime birthday = DateTime.Now.AddYears(-18); // TODO: Initialize to an appropriate value
            string email = "pedro" + rand.Next(400) + "@gmail.com"; // TODO: Initialize to an appropriate value
            //string email = "juan@hotmail.com";
            string password = "qwert1"; // TODO: Initialize to an appropriate value
            string rePassword = "qwert1"; // TODO: Initialize to an appropriate value
            string department = "Cochabamba"; // TODO: Initialize to an appropriate value
            string city = "Cercado"; // TODO: Initialize to an appropriate value
            string movilephone = "" + rand.Next(79999999); // TODO: Initialize to an appropriate value
            string phone = "" + rand.Next(4999999); // TODO: Initialize to an appropriate value
            Collection<RegisterError> ac;
            ac = UserRegistrationManager.RegisterUser(firstName, lastName, gender, birthday, email, password, rePassword, department, city, movilephone, phone);

            GiftCard expected = null;
            User act;
            act = UserDataAccess.GetUserByEmail(email);

            long userIdSender = act.Id;
            long userIdRecipient = act.Id;
            float quantity = 10;
            string currency = "Bolivianos";
            string notification = "Yes";
            string available = "Yes";
            expected = GiftCardManager.NewGiftCard(userIdSender, userIdRecipient, quantity, currency, notification, available);
            bool res = GiftCardManager.UserHasGiftCard(act);
        }

        /// <summary>
        ///A test for GetGiftCardByRecipientId
        ///</summary>
        [TestMethod()]
        public void GetGiftCardByRecipientIdTest()
        {
            string firstName = "Pedro"; // TODO: Initialize to an appropriate value
            string lastName = "Suarez"; // TODO: Initialize to an appropriate value
            char gender = 'M'; // TODO: Initialize to an appropriate value
            Random rand = new Random();
            DateTime birthday = DateTime.Now.AddYears(-18); // TODO: Initialize to an appropriate value
            string email = "pedro" + rand.Next(400) + "@gmail.com"; // TODO: Initialize to an appropriate value
            //string email = "juan@hotmail.com";
            string password = "qwert1"; // TODO: Initialize to an appropriate value
            string rePassword = "qwert1"; // TODO: Initialize to an appropriate value
            string department = "Cochabamba"; // TODO: Initialize to an appropriate value
            string city = "Cercado"; // TODO: Initialize to an appropriate value
            string movilephone = "" + rand.Next(79999999); // TODO: Initialize to an appropriate value
            string phone = "" + rand.Next(4999999); // TODO: Initialize to an appropriate value
            Collection<RegisterError> ac;
            ac = UserRegistrationManager.RegisterUser(firstName, lastName, gender, birthday, email, password, rePassword, department, city, movilephone, phone);

            GiftCard expected = null;
            User act;
            act = UserDataAccess.GetUserByEmail(email);

            long userIdSender = act.Id;
            long userIdRecipient = act.Id;
            float quantity = 10;
            string currency = "Bolivianos";
            string notification = "Yes";
            string available = "Yes";
            expected = GiftCardManager.NewGiftCard(userIdSender, userIdRecipient, quantity, currency, notification, available);
            GiftCard test = GiftCardManager.GetGiftCardByRecipientId(act.Id);
        }

        /// <summary>
        ///A test for NotificationGiftCardToYes
        ///</summary>
        [TestMethod()]
        public void NotificationGiftCardToYesTest()
        {
            string firstName = "Pedro"; // TODO: Initialize to an appropriate value
            string lastName = "Suarez"; // TODO: Initialize to an appropriate value
            char gender = 'M'; // TODO: Initialize to an appropriate value
            Random rand = new Random();
            DateTime birthday = DateTime.Now.AddYears(-18); // TODO: Initialize to an appropriate value
            string email = "pedro" + rand.Next(400) + "@gmail.com"; // TODO: Initialize to an appropriate value
            //string email = "juan@hotmail.com";
            string password = "qwert1"; // TODO: Initialize to an appropriate value
            string rePassword = "qwert1"; // TODO: Initialize to an appropriate value
            string department = "Cochabamba"; // TODO: Initialize to an appropriate value
            string city = "Cercado"; // TODO: Initialize to an appropriate value
            string movilephone = "" + rand.Next(79999999); // TODO: Initialize to an appropriate value
            string phone = "" + rand.Next(4999999); // TODO: Initialize to an appropriate value
            Collection<RegisterError> ac;
            ac = UserRegistrationManager.RegisterUser(firstName, lastName, gender, birthday, email, password, rePassword, department, city, movilephone, phone);

            GiftCard expected = null;
            User act;
            act = UserDataAccess.GetUserByEmail(email);

            long userIdSender = act.Id;
            long userIdRecipient = act.Id;
            float quantity = 10;
            string currency = "Bolivianos";
            string notification = "No";
            string available = "Yes";
            expected = GiftCardManager.NewGiftCard(userIdSender, userIdRecipient, quantity, currency, notification, available);
            GiftCardManager.ChangeNotificationToYes(expected);
        }


    }
}
